import random
random.seed(666)
# 读取原始文件内容
with open('new_data_train.txt', 'r', encoding='utf-8') as f:
    lines = f.readlines()

# 随机打乱数据
random.shuffle(lines)

# 计算划分的索引位置
split_index = int(len(lines) * 0.8)

# 划分数据
train_data = lines[:split_index]
val_data = lines[split_index:]

# 写入train.txt文件
with open('train.txt', 'w', encoding='utf-8') as f:
    f.writelines(train_data)

# 写入val.txt文件
with open('val.txt', 'w', encoding='utf-8') as f:
    f.writelines(val_data)